package com.speedtickets.rest.utils;

import org.codehaus.jettison.json.JSONException;
import org.codehaus.jettison.json.JSONObject;

public class HandleEvents {
	
	public static JSONObject handleNotFoundError(String resourceId) throws JSONException{
		JSONObject json = new JSONObject();
		json.put("httpCode", 404);
		json.put("result", "failure");
		json.put("message", "Resource id " + resourceId + " Not Found");
		return json;
	}

	public static JSONObject handleSucess(Long resourceId, String resourceName, String method, Integer httpCode) throws JSONException{
		JSONObject json = new JSONObject();
		json.put("httpCode", httpCode);
		json.put("result", "sucess");
		json.put("method", method);
		json.put("resource", "http://api.speedtickets.rest/v1/" + resourceName + "/" + resourceId);
		return json;
	}
	
	public static JSONObject handleBadRequest( String exceptionMessage, Integer httpCode ) throws JSONException{
		JSONObject json = new JSONObject();
		json.put("httpCode", httpCode);
		json.put("result", "failure");
		json.put("message", exceptionMessage);
		return json;
	}
	
	public static JSONObject handleUnauthorized( Integer httpCode ) throws JSONException{
		JSONObject json = new JSONObject();
		json.put("httpCode", httpCode);
		json.put("result", "failure");
		json.put("message", "A Valide APIKey is Required To Execute This Operation");
		return json;
	}
	
	public static JSONObject handleForbidden( Integer httpCode ) throws JSONException{
		JSONObject json = new JSONObject();
		json.put("httpCode", httpCode);
		json.put("result", "failure");
		json.put("message", "Operation Forbidden For This APIKey");
		return json;
	} 
	
	public static JSONObject handleServerError( Integer httpCode ) throws JSONException{
		JSONObject json = new JSONObject();
		json.put("httpCode", httpCode);
		json.put("result", "failure");
		json.put("message", "An error occured during this operation");
		return json;
	}
}
